package top.saplf.sileny.main.home

import android.support.v4.app.Fragment
import android.support.v4.app.FragmentManager
import android.support.v4.app.FragmentPagerAdapter
import android.support.v4.app.FragmentStatePagerAdapter

/**
 * @author Saplf on 17/4/14
 */
class SimpleFragmentPagerAdapter(
        fragmentManager: FragmentManager,
        val fragments: List<Fragment>,
        val fragmentTitles: List<String>
) : FragmentStatePagerAdapter(fragmentManager) {
    init {
        if (fragments.size != fragmentTitles.size) {
            throw IllegalStateException("fragments' size is ${fragments.size}, and titles' size is ${fragmentTitles.size}")
        }
    }

    override fun getItem(position: Int): Fragment = fragments[position]

    override fun getPageTitle(position: Int): CharSequence = fragmentTitles[position]

    override fun getCount(): Int = fragments.size
}